package org.alex.samples.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;

@Entity
@Table(name="exam_role")
public class ExamRole implements Serializable {
	
	private static final long serialVersionUID=-8694539773273501319L;
	
	@Id
	@Column(name="role_id",nullable=false)
	@NotNull(message="ID不可以为空！")
	private Integer roleId;
	
	@Column(name="name",length=1000, nullable=false)
	@NotEmpty(message="姓名不可以为空！")
	private String name;
	
	//指定多对多关系,并设置级联关系
		@ManyToMany(cascade={CascadeType.DETACH,CascadeType.PERSIST,CascadeType.MERGE,CascadeType.ALL})    
		@JoinTable(name="exam_user_role",                           //中间表的名称
			joinColumns={@JoinColumn(name="role_id")},				   //本表与中间表的外键对应关系
			inverseJoinColumns={@JoinColumn(name="user_id")})		   //另一张表与中间表的外键的对应关系
		private Set<UserJDBC> userJDBC=new HashSet<UserJDBC>();
	
	

	public static long getSerialversionuid() {
			return serialVersionUID;
		}
	public Integer getRoleId() {
		return roleId;
	}
	public void setRoleId(Integer roleId) {
		this.roleId = roleId;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Set<UserJDBC> getUserJDBC() {
		return userJDBC;
	}
	public void setUserJDBC(Set<UserJDBC> userJDBC) {
		this.userJDBC = userJDBC;
	}
	
	
}
